/* GUI CONVERTED from rcrsupb2.p (converter v1.75) Mon Nov 20 16:58:04 2000 */
/* rcrsupb2.p - Release Management Customer Schedules - SubProgram      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*G1PP*/ /*V8:ConvertMode=Report                                        */
/* REVISION: 9.1   DATE CREATED: 05/20/99 BY: *N003* Patrick Rowan      */
/* REVISION: 9.1  LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1  LAST MODIFIED: 05/02/00 BY: *N09M* Inna Lyubarsky     */
/* REVISION: 9.1  LAST MODIFIED: 08/12/00 BY: *N0KP* myb                */
/*                               09/06/00 BY: *K1Q4* Missing Patch Mark */
/* REVISION: 9.1  LAST MODIFIED: 09/06/00 BY: *N0RG* Rajinder Kamra     */


/*!
 ----------------------------------------------------------------------------
 DESCRIPTION: This program build work-file entries of all the sequences
              for a specific part (on the active release of the sequence
              schedule).  The work-file is used by the RSS update to create
              a new Required Ship Schedule.

 Notes:
 ============================================================================
 !*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdeclre.i}
         {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE rcrsupb2_p_4 "Horizon Date"
/* MaxLen: 20  Comment: The last date of a date range to select sequences. ~
         No sequences will picked with a date greater than the horizon date. */

/*N0RG*
 * &SCOPED-DEFINE rcrsupb2_p_7 "WARNING: No Active Sequence Schedule found"
 * /* MaxLen: 80  Comment: There can be only one active release schedule at a time.~
 *                   If no active schedule is found, then this warning appears. */
 *N0RG*/

/* ********** End Translatable Strings Definitions ********* */

/*N09M --- COMMENTED TRANSLATABLE STRINGS DEFINITIONS ------ *
* &SCOPED-DEFINE rcrsupb2_p_1 " Customer Sequenced Schedule "
* /* MaxLen: 35  Comment: */
*
* &SCOPED-DEFINE rcrsupb2_p_2 " Required Quantities "
* /* MaxLen: 25  Comment: */
*
* &SCOPED-DEFINE rcrsupb2_p_3 " Schedule Detail Data "
* /* MaxLen: 60  Comment: */
*
* &SCOPED-DEFINE rcrsupb2_p_5 "Ship From: "
* /* MaxLen: 20  Comment: */
*
* &SCOPED-DEFINE rcrsupb2_p_6 "    Ship To: "
* /* MaxLen: 20  Comment: */
*
* &SCOPED-DEFINE rcrsupb2_p_8 "Seq Release ID: "
* /* MaxLen: 20  Comment: Displays the Sequence Schedule Release ID. */
*N09M ------------------------------------------------------ */



         /*! REQUIRED SCHEDULE UPDATE SUBPROGRAM */

         define input parameter sonbr like so_nbr no-undo.
         define input parameter soline like sod_line no-undo.
         define input parameter rlseid like rcs_rlse_id no-undo.
         define output parameter out_datetype like rcs_date_type no-undo.

         define variable i as integer no-undo.

         define shared variable report_yn like mfc_logical.
         define shared variable warn_ct as integer no-undo.

         define variable l_total_discr_qty like rcsd_discr_qty no-undo.
         define variable l_total_cum_qty like rcsd_cum_qty no-undo.
         define variable l_firm_days like rcf_firm_seq_days no-undo.
         define variable l_desc1 like pt_desc1 no-undo.
         define variable l_horizon_date like rcsd_date no-undo
                                label {&rcrsupb2_p_4}.
/*N09M*/ define variable req_qty as character no-undo format "x(25)".

         /* THIS WORKFILE IS CLEARED OUT IN THE CALLING ROUTINE */
         define shared workfile work_seq_schd no-undo
            field work_seq_week_date like schd_date
            field work_seq_date like schd_date
            field work_seq_time like schd_time format "XX:XX"
            field work_seq_reference like schd_reference
            field work_seq_qty like schd_upd_qty
            field work_seq_cum_qty like schd_cum_qty
            field work_seq_rlse_id as character
            field work_seq_recid as recid
            field work_seq_cmtindx like sch_cmtindx.

/*N0RG*/ define variable l_msg   as character no-undo format "x(60)".

/*N0RG*/ /* No active sequence schedule found */
/*N0RG*/ {pxmsg.i &MSGNUM=4553 &ERRORLEVEL=2 &MSGBUFFER=l_msg}

/*N09M*/ req_qty = " " + getTermLabel("REQUIRED_QUANTITIES",25) + " ".
        FORM /*GUI*/ 
            {rcordfma.i}
            skip(.4)      
            sch_rlse_id colon 46
            skip(.4)      
            with STREAM-IO /*GUI*/  frame prm side-labels width 80 attr-space
/*V8+*/
            .

            /* SET EXTERNAL LABELS */
            setFrameLabels(frame prm:handle).

         FORM /*GUI*/ 
            rcsd_date
            rcsd_time
            work_seq_reference
            l_total_discr_qty
            with STREAM-IO /*GUI*/  frame schd1c down attr-space
            width 80 title color normal
            (getFrameTitle("SCHEDULE_DETAIL_DATA",29)).

            /* SET EXTERNAL LABELS */
            setFrameLabels(frame schd1c:handle).

         /* INITIALIZE */
         assign
            l_total_discr_qty = 0
            l_total_cum_qty = 0.
         clear frame schd1c all no-pause.

         /* GET CURRENT RECORDS */
         for first so_mstr fields (so_firm_seq_days)
            where
                so_nbr = sonbr no-lock: end.
         for first sod_det fields (sod_custpart sod_desc)
            where
                sod_nbr = sonbr and sod_line = soline no-lock: end.
         for first sch_mstr fields (sch_rlse_id)
            where
                sch_nbr = sonbr and sch_line = soline no-lock: end.
         for first scx_ref
            where
                scx_order = sonbr and scx_line = soline and
                scx_type = 1 no-lock: end.
         for first rcf_ctrl fields (rcf_firm_seq_days) no-lock: end.

         /* GET NUMBER OF FIRM DAYS OF THE SCHEDULE */
         l_firm_days = so_firm_seq_days.

         /* GET ACTIVE RELEASE OR SPECIFIC RELEASE */
         if rlseid = "" then
            for last rcs_mstr where
                rcs_shipfrom = scx_shipfrom  and
                rcs_shipto   = scx_shipto    and
                rcs_active                   no-lock: end.
         else
            for last rcs_mstr where
                rcs_shipfrom = scx_shipfrom  and
                rcs_shipto   = scx_shipto    and
                rcs_rlse_id  = rlseid        no-lock: end.

         if not available (rcs_mstr) then do:
            put unformatted skip(1)
/*N0RG       {&rcrsupb2_p_7} */
/*N0RG*/     l_msg
            skip
/*N09M      {&rcrsupb2_p_5} + scx_shipfrom + {&rcrsupb2_p_6} + scx_shipto */
/*N09M* ------- ADDED CODE ---------------------------------------------- */
            {gplblfmt.i
        &FUNC=getTermLabel(""SHIP_FROM"",18)
        &CONCAT="': '"
        } + scx_shipfrom + " "
        getTermLabelRt("SHIP_TO",14) + ": " format "x(16)"
        + scx_shipto
/*N09M* ----------------------------------------------------------------- */
            skip(1).
            warn_ct = warn_ct + 1.

         end.  /* END - if not available (rcs_mstr) */
         else do:   /* available (rcs_mstr) */

            /* REPORT HEADER */
            if report_yn then do:
                for first ad_mstr fields (ad_name)
                    where
                        ad_addr = scx_shipto no-lock: end.

                for first pt_mstr fields (pt_um pt_desc1)
                    where
                        pt_part = scx_part no-lock: end.
                if available (pt_mstr) then
                    l_desc1 = pt_desc1.
                else
                    if available sod_det then
                        l_desc1 = sod_desc.
                    else
                        l_desc1 = "".

                /* CALCULATE TIME HORIZON DATE, IF FIRM DAYS ARE USED */
                if l_firm_days > 0 then do:

                    do i = 1 to l_firm_days:

                        if i = 1 then do:

                            /* INITIALIZE THE STARTING DATE */

                            /* READ FIRST SEQUENCED SCHEDULE RECORD */
                            for first rcsd_det where
                                rcsd_rlse_id  = rcs_rlse_id   and
                                rcsd_shipfrom = rcs_shipfrom  and
                                rcsd_shipto   = rcs_shipto    and
                                rcsd_order    = scx_order     and
                                rcsd_line     = scx_line      and
                                rcsd_part     = scx_part
                                use-index rcsd_index3
                                no-lock: end.

                            /* SET THE HORIZON DATE */
                            if available (rcsd_det) then
                                l_horizon_date = rcsd_date.
                            else
                                l_horizon_date = today.

                        end.  /* if i = 1 */
                        else

                            /* ADD TO THE HORIZON DATE */
                            l_horizon_date = l_horizon_date + 1.

                        /* CALL mfhdate.i DAY-BY-DAY TO ADJUST FOR  */
                        /* WEEKENDS AND HOILIDAYS IN SHOP CALENDAR  */
                        {mfhdate.i l_horizon_date +1 scx_shipfrom}
                    end.
                end.  /* if l_firm_days > 0 */

                display {1}
                   scx_shipfrom
                   scx_shipto
                   ad_name          when (available ad_mstr)
                   scx_part
                   l_desc1    @ sod_desc
                   sod_custpart     when (available sod_det)
                   pt_um            when (available pt_mstr)
                   scx_po
                   rcs_rlse_id  @ sch_rlse_id
                   scx_order
                   scx_line
                   with frame prm STREAM-IO /*GUI*/ .

             do with frame sched1_data:
        /* SET EXTERNAL LABELS */
                setFrameLabels(frame sched1_data:handle).
                display
                    rcs_date_type       colon 20
                    rcs_cr_date         colon 55
                    rcs_cr_time         no-label
                    rcs_active_start    colon 20
                    rcs_cumulative      colon 55
                    rcs_active_end      colon 20
                    with frame sched1_data attr-space
                    side-labels width 80 STREAM-IO /*GUI*/ .
              end. /* do with */

                if l_firm_days > 0 then do with frame sched2_data:
                    /* SET EXTERNAL LABELS */
                    setFrameLabels(frame sched2_data:handle).
                    display
                        l_firm_days         colon 20
                        l_horizon_date      colon 55
                    with frame sched2_data attr-space
                    side-labels width 80 STREAM-IO /*GUI*/ .
                end. /* if l_firm_days > 0 then */

            end.  /* END - if report_yn */
            else
                display
/*N09M              {&rcrsupb2_p_8} at 1 */
/*N09M*/            getTermLabel("SEQUENCE_RELEASE_ID",19) format "x(19)" at 1
                    rcs_rlse_id
                    skip(1) with no-box no-labels down STREAM-IO /*GUI*/ .

            out_datetype = rcs_date_type.

            /* READ SEQUENCED SCHEDULE DATA */
            for each rcsd_det where
                rcsd_rlse_id  = rcs_rlse_id   and
                rcsd_shipfrom = rcs_shipfrom  and
                rcsd_shipto   = rcs_shipto    and
                rcsd_order    = scx_order     and
                rcsd_line     = scx_line      and
                rcsd_part     = scx_part      and
                (not rcsd_picked)             and
                (not rcsd_delete)             and
                (not rcsd_x_referenced)
                use-index rcsd_index3
                break by rcsd_date
                      by rcsd_time:

                 /* VERIFY SEQUENCE IS WITHIN TIME HORIZON */
                 if l_firm_days = 0 or
                   (l_firm_days > 0 and rcsd_date <= l_horizon_date)
                    then do:

                    /* INCREMENT TOTALS */
                    assign
                        l_total_discr_qty = l_total_discr_qty +
                                            rcsd_discr_qty.
                        l_total_cum_qty = l_total_cum_qty +
                                          l_total_discr_qty.

                    if last-of(rcsd_date) or
                       last-of(rcsd_time) then do:

                        /* ADD TO WORK FILE */
                        create work_seq_schd.
                        assign
                            work_seq_date       = rcsd_date
                            work_seq_time       = rcsd_time
                            work_seq_rlse_id    = rcsd_rlse_id
                            work_seq_recid      = recid(rcsd_det)
                            work_seq_qty        = l_total_discr_qty
                            work_seq_cum_qty    = l_total_cum_qty.

                        if recid(work_seq_schd) = -1 then .

                        /*! SET MONDAY DATES FOR THE WEEK */
                        {gprun.i ""rswmd.p"" "(input work_seq_date, input yes,
                        output work_seq_week_date)"}

                        /* REPORT DETAIL */
                        if report_yn then do:
                            display
                                rcsd_date
                                rcsd_time
                                "" @ work_seq_reference
                                l_total_discr_qty
                                with frame schd1c STREAM-IO /*GUI*/ .
                            down 1 with frame schd1c.
                        end.  /* END - if report_yn */

                        /* RESET TOTALS */
                        l_total_discr_qty = 0.

                    end.  /* if last-of(rcsd_date) or last-of(rcsd_time) */

                 end.  /* END - if l_firm_days = 0 or... */

            end.  /* END - for each rcsd_det */

            page.

         end.  /* END - available (rcs_mstr) */
